package test;

import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.kernel.Config;
import com.alipay.easysdk.kernel.util.ResponseChecker;
import com.alipay.easysdk.payment.page.models.AlipayTradePagePayResponse;

import java.util.ResourceBundle;
import java.util.UUID;

public class test {

    public static void main(String[] args) {

        com.alipay.easysdk.factory.Factory.setOptions(test.setOPtion());
        try {

            String id=UUID.randomUUID().toString();
            String returnurl="http";
            AlipayTradePagePayResponse response= Factory.Payment.Page().pay("测试",id,"12",returnurl);
            // 3. 处理响应或异常
            if (ResponseChecker.success(response)) {
                System.out.println(response);

                System.out.println(response.getBody());
                System.out.println("调用成功");
            } else {
                System.err.println("调用失败，原因：" + response.toString());
            }
        } catch (Exception e) {
            System.err.println("调用遭遇异常，原因：" + e.getMessage());
            throw new RuntimeException(e.getMessage(), e);
        }
    }

    private static Config setOPtion(){
        ResourceBundle res= ResourceBundle.getBundle("conf/pay");
        Config f=new Config();
        f.alipayPublicKey= res.getString("alipayPublicKey");
        f.appId=res.getString("appid");
        f.merchantPrivateKey=res.getString("privateKey");
        f.protocol = "https";
        f.gatewayHost = "openapi.alipaydev.com";
        f.signType = "RSA2";
        f.notifyUrl="http";
        return f;
    }
}
